package com.excesys.exsecs.eco.util;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import io.netty.util.internal.StringUtil;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.*;

import static cn.hutool.core.date.DateTime.now;

public class DateUtil {

	private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	private static final Set<LocalDate> HOLIDAYS = new HashSet<>();

	/**
	 * 获取当月的 天数
	 */

	public static int getCurrentMonthDay() {

		Calendar a = Calendar.getInstance();

		a.set(Calendar.DATE, 1);

		a.roll(Calendar.DATE, -1);

		int maxDate = a.get(Calendar.DATE);

		return maxDate;

	}

	/**
	 * 根据年 月 获取对应的月份 天数
	 */

	public static int getDaysByYearMonth(int year, int month) {

		Calendar a = Calendar.getInstance();

		a.set(Calendar.YEAR, year);

		a.set(Calendar.MONTH, month - 1);

		a.set(Calendar.DATE, 1);

		a.roll(Calendar.DATE, -1);

		int maxDate = a.get(Calendar.DATE);

		return maxDate;

	}

	/**
	 * 根据日期 找到对应日期的 星期
	 */

	public static String getDayOfWeekByDate(String date) {

		String dayOfweek = "-1";

		try {

			SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");

			Date myDate = myFormatter.parse(date);

			SimpleDateFormat formatter = new SimpleDateFormat("E");

			String str = formatter.format(myDate);

			dayOfweek = str;

		}
		catch (Exception e) {

			System.out.println("错误!");

		}

		return dayOfweek;

	}

	/**
	 * 获取当前时间小时整点时间
	 * @param
	 * @return
	 */
	public static String getCurrentHourTime(int n) {
		Date CurrentHourTime = getHourTime(new Date(), n, "=");
		return sdf.format(CurrentHourTime);

	}

	/**
	 * 获取指定时间上n个小时整点时间
	 * @param date
	 * @return
	 */
	public static String getLastHourTime(Date date, int n) {
		Date LastHourTime = getHourTime(date, n, "-");
		return sdf.format(LastHourTime);
	}

	/**
	 * 获取指定时间下n个小时整点时间
	 * @param date
	 * @return
	 */
	public static String getNextHourTime(Date date, int n) {
		Date NextHourTime = getHourTime(date, n, "+");
		return sdf.format(NextHourTime);
	}

	/**
	 * 获取指定时间n个小时整点时间
	 * @param date
	 * @return
	 */
	public static Date getHourTime(Date date, int n, String direction) {
		Calendar ca = Calendar.getInstance();
		ca.setTime(date);
		ca.set(Calendar.MINUTE, 0);
		ca.set(Calendar.SECOND, 0);
		switch (direction) {
			case "+":
				ca.set(Calendar.HOUR_OF_DAY, ca.get(Calendar.HOUR_OF_DAY) + n);
				break;
			case "-":
				ca.set(Calendar.HOUR_OF_DAY, ca.get(Calendar.HOUR_OF_DAY) - n);
				break;
			case "=":
				ca.set(Calendar.HOUR_OF_DAY, ca.get(Calendar.HOUR_OF_DAY));
				break;
			default:
				ca.set(Calendar.HOUR_OF_DAY, ca.get(Calendar.HOUR_OF_DAY));
		}

		date = ca.getTime();
		return date;
	}

	/**
	 * 将当前时间的秒变为00，例如16:41:00
	 * @param date
	 * @return
	 */
	public static Date getSecondPoint(Date date) {
		Calendar ca = Calendar.getInstance();
		ca.setTime(date);
		ca.set(Calendar.SECOND, 0);
		ca.set(Calendar.HOUR_OF_DAY, ca.get(Calendar.HOUR_OF_DAY));
		return ca.getTime();
	}

	// 获取当天的开始时间，例如：2022-05-06 00:00:00
	public static String getLocalDateStartTime() {
		LocalDateTime startTime = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
		return startTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
	}

	// 获取当天的结束时间，例如：2022-05-06 23:59:59
	public static String getLocalDateEndTime() {
		LocalDateTime startTime = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
		return startTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
	}

	// 获取当天的前一天开始时间，例如：2022-05-06 00:00:00
	public static String getLocalDateBeforeDayStartTime() {
		LocalDate localDate = LocalDate.now().minusDays(1);
		return localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd 00:00:00"));
	}

	// 获取当天的结束时间，例如：2022-05-06 23:59:59
	public static String getLocalDateBeforeDayEndTime() {
		LocalDate localDate = LocalDate.now().minusDays(1);
		return localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd 23:59:59"));
	}

	// 获取上n个小时的开始时间，上一个小时，amount=-60
	public static String getBeforeHourStartTime(int amount) {
		Date date = org.apache.commons.lang3.time.DateUtils.addMinutes(now(), amount);
		return new SimpleDateFormat("yyyy-MM-dd HH:00:00").format(date);
	}

	// 获取上n个小时的结束时间，上一个小时，amount=-60
	public static String getBeforeHourEndTime(int amount) {
		Date date = org.apache.commons.lang3.time.DateUtils.addMinutes(now(), amount);
		return new SimpleDateFormat("yyyy-MM-dd HH:59:59").format(date);
	}

	// 获取某一年的开始时间，例如：2022-01-01 00:00:00
	public static String getBeginDayOfYear(String date) {
		LocalDate today;
		if (null == date) {
			today = LocalDate.now();
		}
		else {
			DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");
			today = LocalDate.parse(date, fmt);
		}
		today = LocalDate.of(today.getYear(), Month.JANUARY, 1);
		LocalDateTime localDateTime = today.atTime(00, 00, 00);
		String format = localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
		return format;
	}

	// 获取m某一年的结束时间，例如：2022-12-31 23:59:59
	public static String getEndDayOfYear(String date) {
		LocalDate today;
		if (null == date) {
			today = LocalDate.now();
		}
		else {
			DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");
			today = LocalDate.parse(date, fmt);
		}
		today = LocalDate.of(today.getYear(), Month.DECEMBER, Month.DECEMBER.length(today.isLeapYear()));
		LocalDateTime localDateTime = today.atTime(23, 59, 59);
		String format = localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
		return format;
	}

	// 判断是否是整点
	public static boolean oClock(DateTime time) {
		SimpleDateFormat sdf = new SimpleDateFormat("mm:ss");
		String timestr = sdf.format(time);
		if (timestr.equals("00:00")) {
			return true;
		}
		else {
			return false;
		}
	}

	// 判断是否是00:00:00的时间
	public static boolean oClockDay(DateTime time) {
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
		String timestr = sdf.format(time);
		if (timestr.equals("00:00:00")) {
			return true;
		}
		else {
			return false;
		}
	}

	// 判断是否是xxxx-xx-01 00:00:00的时间（月的起始时间）
	public static boolean oClockMonth(DateTime time) {
		SimpleDateFormat sdf = new SimpleDateFormat("dd HH:mm:ss");
		String timestr = sdf.format(time);
		if (timestr.equals("01 00:00:00")) {
			return true;
		}
		else {
			return false;
		}
	}

	// 判断是否是xxxx-01-01 00:00:00的时间（年的起始时间）
	public static boolean oClockYear(DateTime time) {
		SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm:ss");
		String timestr = sdf.format(time);
		if (timestr.equals("01-01 00:00:00")) {
			return true;
		}
		else {
			return false;
		}
	}

	/***
	 * 判断和已知时刻进行对比
	 * @param time 当前时间
	 * @param HHmm HH:mm
	 * @return
	 */
	public static boolean timeEquals(DateTime time, String HHmm) {
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
		String timestr = sdf.format(time);
		if (timestr.equals(HHmm)) {
			return true;
		}
		else {
			return false;
		}
	}

	/***
	 * 判断和已知时刻进行对比
	 * @param time 当前时间
	 * @param ddHHmm dd:HH:mm
	 * @return
	 */
	public static boolean dayEquals(DateTime time, String ddHHmm) {
		SimpleDateFormat sdf = new SimpleDateFormat("dd HH:mm");
		String timestr = sdf.format(time);
		if (timestr.equals(ddHHmm)) {
			return true;
		}
		else {
			return false;
		}
	}

	/***
	 * 判断和已知时刻进行对比
	 * @param time 当前时间
	 * @param MMddHHmm dd:HH:mm
	 * @return
	 */
	public static boolean monthEquals(DateTime time, String MMddHHmm) {
		SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm");
		String timestr = sdf.format(time);
		if (timestr.equals(MMddHHmm)) {
			return true;
		}
		else {
			return false;
		}
	}

	// 判断是否是整点过10分钟的时间：比如12:10:00
	public static boolean oClockafterTenminute(DateTime time) {
		SimpleDateFormat sdf = new SimpleDateFormat("mm:ss");
		String timestr = sdf.format(time);
		if (timestr.equals("10:00")) {
			return true;
		}
		else {
			return false;
		}
	}

	// 获取某天每个小时的时间点:[2022052500, 2022052501, 2022052502, 2022052503, 2022052504,
	// 2022052505.。。2022052523, 2022052600]
	public static List<String> getHours(String dateStr) {
		Date date = null;
		if (!StringUtil.isNullOrEmpty(dateStr)) {
			date = cn.hutool.core.date.DateUtil.parse(dateStr, "yyyy-MM-dd");
		}
		else {
			date = new Date();
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHH");
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.DAY_OF_MONTH, 0);
		date = calendar.getTime();
		String format = null;
		List<String> strings = new ArrayList<>();
		for (int i = 0; i <= 24; i++) {
			date.setHours(i);
			format = sdf.format(date);
			strings.add(format);
		}
		return strings;
	}

	// 获取某天每个小时的时间点:[2022-05-25 00, 2022-05-25 01, 2022052502, 2022052503, 2022052504,
	// 2022052505.。。2022052523, 2022052600]
	public static List<String> getHours2(String dateStr) {
		Date date = null;
		if (!StringUtil.isNullOrEmpty(dateStr)) {
			date = cn.hutool.core.date.DateUtil.parse(dateStr, "yyyy-MM-dd");
		}
		else {
			date = new Date();
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH");
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.DAY_OF_MONTH, 0);
		date = calendar.getTime();
		String format = null;
		List<String> strings = new ArrayList<>();
		for (int i = 0; i <= 24; i++) {
			date.setHours(i);
			format = sdf.format(date);
			strings.add(format);
		}
		return strings;
	}

	// 获取某天每隔两小时的时间点:[2022052500, 2022052502, 2022052504, 2022052506, 2022052508,
	// 2022052510, 2022052512, 2022052514,
	// 2022052516, 2022052518, 2022052520, 2022052522, 2022052600]
	public static List<String> getTwoHours(String dateStr) {
		Date date = null;
		if (!StringUtil.isNullOrEmpty(dateStr)) {
			date = cn.hutool.core.date.DateUtil.parse(dateStr, "yyyy-MM-dd");
		}
		else {
			date = new Date();
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHH");
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.DAY_OF_MONTH, 0);
		date = calendar.getTime();
		String format = null;
		List<String> strings = new ArrayList<>();
		for (int i = 0; i <= 24; i++) {
			if (i % 2 != 0) {
				continue;
			}
			date.setHours(i);
			format = sdf.format(date);
			strings.add(format);
		}
		return strings;
	}

	// 获取当月的每一天
	public static List<String> getDayOfMonth(String dateStr) {
		List list = new ArrayList();
		Date date = null;
		if (!StringUtil.isNullOrEmpty(dateStr)) {
			date = cn.hutool.core.date.DateUtil.parse(dateStr, "yyyy-MM");
		}
		else {
			date = new Date();
		}
		Calendar aCalendar = Calendar.getInstance();
		aCalendar.setTime(date);
		int year = aCalendar.get(Calendar.YEAR);// 年份
		int month = aCalendar.get(Calendar.MONTH) + 1;// ⽉份
		int day = aCalendar.getActualMaximum(Calendar.DATE);
		for (int i = 1; i <= day; i++) {
			String aDate = null;
			if (month < 10 && i < 10) {
				aDate = String.valueOf(year) + "0" + month + "0" + i;
			}
			if (month < 10 && i >= 10) {
				aDate = String.valueOf(year) + "0" + month + "" + i;
			}
			if (month >= 10 && i < 10) {
				aDate = String.valueOf(year) + "" + month + "0" + i;
			}
			if (month >= 10 && i >= 10) {
				aDate = String.valueOf(year) + "" + month + "" + i;
			}
			list.add(aDate);
		}
		return list;
	}

	// 获取当月的每一天
	public static List<String> getDayOfMonth2(String dateStr) {
		List list = new ArrayList();
		Date date = null;
		if (!StringUtil.isNullOrEmpty(dateStr)) {
			date = cn.hutool.core.date.DateUtil.parse(dateStr, "yyyy-MM");
		}
		else {
			date = new Date();
		}
		Calendar aCalendar = Calendar.getInstance();
		aCalendar.setTime(date);
		int year = aCalendar.get(Calendar.YEAR);// 年份
		int month = aCalendar.get(Calendar.MONTH) + 1;// ⽉份
		int day = aCalendar.getActualMaximum(Calendar.DATE);
		for (int i = 1; i <= day; i++) {
			String aDate = null;
			if (month < 10 && i < 10) {
				aDate = String.valueOf(year) + "-0" + month + "-0" + i;
			}
			if (month < 10 && i >= 10) {
				aDate = String.valueOf(year) + "-0" + month + "-" + i;
			}
			if (month >= 10 && i < 10) {
				aDate = String.valueOf(year) + "-" + month + "-0" + i;
			}
			if (month >= 10 && i >= 10) {
				aDate = String.valueOf(year) + "-" + month + "-" + i;
			}
			list.add(aDate);
		}
		return list;
	}

	// 获取当年的每一个月
	public static List<String> getMonthsOfYear(String dateStr) {
		int year = 0;
		List list = new ArrayList();
		if (!StringUtil.isNullOrEmpty(dateStr)) {
			year = Integer.parseInt(dateStr);
		}
		else {
			LocalDate date = LocalDate.now();
			year = date.getYear();
		}

		for (int i = 1; i <= 12; i++) {
			String aDate = null;
			if (i < 10) {
				aDate = String.valueOf(year) + "0" + i;
			}
			else {
				aDate = String.valueOf(year) + "" + i;
			}
			list.add(aDate);
		}
		return list;
	}

	// 获取当年的每一个月
	public static List<String> getMonthsOfYear2(String dateStr) {
		int year = 0;
		List list = new ArrayList();
		if (!StringUtil.isNullOrEmpty(dateStr)) {
			year = Integer.parseInt(dateStr);
		}
		else {
			LocalDate date = LocalDate.now();
			year = date.getYear();
		}

		for (int i = 1; i <= 12; i++) {
			String aDate = null;
			if (i < 10) {
				aDate = String.valueOf(year) + "-0" + i;
			}
			else {
				aDate = String.valueOf(year) + "-" + i;
			}
			list.add(aDate);
		}
		return list;
	}

	// 获取上一天的日期
	public static String getLastDay(String dateStr) {
		LocalDate parse = LocalDate.parse(dateStr, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
		return parse.minusDays(1).atStartOfDay().atZone(ZoneId.systemDefault())
				.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
	}

	// 获取上个月的最后一天
	public static String getLastDayOfMonth(String dateStr) {
		LocalDate date = null;
		if (!StringUtil.isNullOrEmpty(dateStr)) {
			try {
				Date dates = new SimpleDateFormat("yyyy-MM").parse(dateStr);
				Instant instant = dates.toInstant();
				ZoneId zoneId = ZoneId.systemDefault();
				date = instant.atZone(zoneId).toLocalDate();
			}
			catch (ParseException e) {
				e.printStackTrace();
			}
		}
		else {
			date = LocalDate.now();
		}
		LocalDate lastMonth = date.minusMonths(1);
		LocalDate lastLocalDate = lastMonth.with(TemporalAdjusters.lastDayOfMonth());
		return lastLocalDate.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
	}

	// 判断传入的日期是否大于当天
	public static boolean isAfterCurrent(String dateStr) {
		LocalDate parse = LocalDate.parse(dateStr, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
		if (parse.getMonth() == LocalDate.now().getMonth() && parse.isAfter(LocalDate.now())) {
			return true;
		}
		return false;
	}

	// 根据开始时间和结束时间获取该时间范围的日期
	public static List<String> getListByTwoDate(String starttime, String endtime, String sign) {
		List<String> dateList = new ArrayList<>();
		if ("1".equalsIgnoreCase(sign)) {
			List<String> twoHours = getHours(starttime);
			for (int i = 0; i < twoHours.size(); i++) {
				if (i == twoHours.size() - 1) {
					dateList.add("24");
				}
				else {
					String str = twoHours.get(i).substring(twoHours.get(i).length() - 2, twoHours.get(i).length());
					dateList.add(str);
				}
			}
		}
		else if ("2".equalsIgnoreCase(sign)) {
			long betweenDay = cn.hutool.core.date.DateUtil.betweenDay(
					cn.hutool.core.date.DateUtil.parse(starttime, "yyyy-MM-dd"),
					cn.hutool.core.date.DateUtil.parse(endtime, "yyyy-MM-dd"), true);
			for (int i = 0; i <= betweenDay; i++) {
				DateTime dateTime = cn.hutool.core.date.DateUtil
						.offsetDay(cn.hutool.core.date.DateUtil.parse(starttime), i);
				dateList.add(cn.hutool.core.date.DateUtil.format(dateTime, "yyyyMMdd"));
			}
		}
		else if ("3".equalsIgnoreCase(sign)) {
			long betweenMonth = cn.hutool.core.date.DateUtil.betweenMonth(
					cn.hutool.core.date.DateUtil.parse(starttime, "yyyy-MM-dd"),
					cn.hutool.core.date.DateUtil.parse(endtime, "yyyy-MM-dd"), true);
			for (int i = 0; i <= betweenMonth; i++) {
				DateTime dateTime = cn.hutool.core.date.DateUtil
						.offsetMonth(cn.hutool.core.date.DateUtil.parse(starttime), i);
				dateList.add(cn.hutool.core.date.DateUtil.format(dateTime, "yyyyMM"));
			}
		}
		else if ("4".equalsIgnoreCase(sign)) {
			long betweenYear = cn.hutool.core.date.DateUtil.betweenYear(
					cn.hutool.core.date.DateUtil.parse(starttime, "yyyy-MM-dd"),
					cn.hutool.core.date.DateUtil.parse(endtime, "yyyy-MM-dd"), true);
			for (int i = 0; i <= betweenYear; i++) {
				DateTime dateTime = cn.hutool.core.date.DateUtil.offset(cn.hutool.core.date.DateUtil.parse(starttime),
						DateField.YEAR, i);
				dateList.add(cn.hutool.core.date.DateUtil.format(dateTime, "yyyy"));
			}
		}
		return dateList;
	}

	// 根据开始时间和结束时间获取该时间范围的日期
	public static List<String> getListByTwoDate2(String starttime, String endtime, String sign) {
		List<String> dateList = new ArrayList<>();
		if ("1".equalsIgnoreCase(sign)) {
			List<String> twoHours = getHours(starttime);
			for (int i = 0; i < twoHours.size(); i++) {
				if (i == twoHours.size() - 1) {
					dateList.add("24");
				}
				else {
					String str = twoHours.get(i).substring(twoHours.get(i).length() - 2, twoHours.get(i).length());
					dateList.add(str);
				}
			}
		}
		else if ("2".equalsIgnoreCase(sign)) {
			long betweenDay = cn.hutool.core.date.DateUtil.betweenDay(
					cn.hutool.core.date.DateUtil.parse(starttime, "yyyy-MM-dd"),
					cn.hutool.core.date.DateUtil.parse(endtime, "yyyy-MM-dd"), true);
			for (int i = 0; i <= betweenDay; i++) {
				DateTime dateTime = cn.hutool.core.date.DateUtil
						.offsetDay(cn.hutool.core.date.DateUtil.parse(starttime), i);
				dateList.add(cn.hutool.core.date.DateUtil.format(dateTime, "yyyy-MM-dd"));
			}
		}
		else if ("3".equalsIgnoreCase(sign)) {
			long betweenMonth = cn.hutool.core.date.DateUtil.betweenMonth(
					cn.hutool.core.date.DateUtil.parse(starttime, "yyyy-MM-dd"),
					cn.hutool.core.date.DateUtil.parse(endtime, "yyyy-MM-dd"), true);
			for (int i = 0; i <= betweenMonth; i++) {
				DateTime dateTime = cn.hutool.core.date.DateUtil
						.offsetMonth(cn.hutool.core.date.DateUtil.parse(starttime), i);
				dateList.add(cn.hutool.core.date.DateUtil.format(dateTime, "yyyy-MM"));
			}
		}
		else if ("4".equalsIgnoreCase(sign)) {
			long betweenYear = cn.hutool.core.date.DateUtil.betweenYear(
					cn.hutool.core.date.DateUtil.parse(starttime, "yyyy-MM-dd"),
					cn.hutool.core.date.DateUtil.parse(endtime, "yyyy-MM-dd"), true);
			for (int i = 0; i <= betweenYear; i++) {
				DateTime dateTime = cn.hutool.core.date.DateUtil.offset(cn.hutool.core.date.DateUtil.parse(starttime),
						DateField.YEAR, i);
				dateList.add(cn.hutool.core.date.DateUtil.format(dateTime, "yyyy"));
			}
		}
		return dateList;
	}

	/***
	 * 获取指定月份的天集合
	 * @param yyyymm 月份参数
	 * @param yearMonth 为true时返回格式yyyyMMdd，为false返回格式dd不带年月
	 * @return
	 */
	public static List<String> getDayListOfMonth(String yyyymm, boolean yearMonth) {

		if (yyyymm.length() != 6) {
			return null;
		}

		List<String> list = new ArrayList<>();
		String ystr = yyyymm.substring(0, 4);
		String mstr = yyyymm.substring(4, 6);

		Calendar a = Calendar.getInstance();
		a.set(Calendar.YEAR, Integer.parseInt(ystr));// 年份
		a.set(Calendar.MONTH, Integer.parseInt(mstr) - 1);// 月份
		a.set(Calendar.DATE, 1);
		a.roll(Calendar.DATE, -1);

		int maxDate = a.get(Calendar.DATE);

		for (int i = 0; i < maxDate; i++) {
			int d = i + 1;
			String dstr = "";
			if (d < 10) {
				dstr = "0" + d;
			}
			else {
				dstr = String.valueOf(d);
			}
			String day = ystr + mstr + dstr;
			if (!yearMonth) {
				day = dstr;
			}
			list.add(day);
		}

		return list;
	}

	public static String getSeasonByDate() {
		EnumSet<Month> spring = EnumSet.of(Month.MARCH, Month.APRIL, Month.MAY);
		EnumSet<Month> summer = EnumSet.of(Month.JUNE, Month.JULY, Month.AUGUST);
		EnumSet<Month> fall = EnumSet.of(Month.SEPTEMBER, Month.OCTOBER, Month.NOVEMBER);
		EnumSet<Month> winter = EnumSet.of(Month.DECEMBER, Month.JANUARY, Month.FEBRUARY);
		ZoneId zoneId = ZoneId.of("Asia/Shanghai");
		Month month = Month.from(ZonedDateTime.now(zoneId));
		if (spring.contains(month)) {
			return "spring";
		} else if (summer.contains(month)) {
			return "summer";
		} else if (fall.contains(month)) {
			return "fall";
		} else if (winter.contains(month)) {
			return "winter";
		} else {
			return null;
		}
	}

	// 判断两个时间区间是否有包含关系或交集
	public static boolean overlapsOrContains(LocalDate AStart, LocalDate AEnd, LocalDate BStart, LocalDate BEnd) {
		// 情况1: A包含B
		if (AStart.isBefore(BStart) && AEnd.isAfter(BEnd)) {
			return true;
		}
		// 情况2: B包含A
		else if (BStart.isBefore(AStart) && BEnd.isAfter(AEnd)) {
			return true;
		}
		// 情况3: A与B有交集
		else if ((AStart.isBefore(BEnd) && AEnd.isAfter(BStart)) ||
				(BStart.isBefore(AEnd) && BEnd.isAfter(AStart))) {
			return true;
		}
		// 如果上述情况都不满足，那么A与B处于不同的时间段
		else {
			return false;
		}
	}

	// 给定起始日期和结束日期，将区间内的日期放入list集合中
	public static List<LocalDate> generateDatesInRange(LocalDate startDate, LocalDate endDate) {
		List<LocalDate> dates = new ArrayList<>();
		LocalDate currentDate = startDate;

		while (!currentDate.isAfter(endDate)) {
			dates.add(currentDate);
			currentDate = currentDate.plusDays(1);
		}

		return dates;
	}

	/**
	 * 判断起始日期和结束日期是否跨年
	 * @return 如果跨年则返回true，否则返回false
	 */
	public static boolean isCrossYear(String startDate, String endDate) {
		LocalDate start = LocalDate.parse(startDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
		LocalDate end = LocalDate.parse(endDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
		return start.getYear() != end.getYear();
	}

	/**
	 * 判断起始日期和结束日期是否跨月
	 * @return 如果跨月则返回true，否则返回false
	 */
	public static boolean isCrossMonth(String startDate, String endDate) {
		LocalDate start = LocalDate.parse(startDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
		LocalDate end = LocalDate.parse(endDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
		// 检查月份是否不同
		if (start.getMonthValue() != end.getMonthValue()) {
			return true;
		}
		return false;
	}

	/**
	 * 获取两个月份之间的所有月份(含跨年)
	 *
	 * @param minDate 开始时间  格式 2022-02或 2022-01-03
	 * @param maxDate 结束时间  格式 2023-08 或2022-02-03
	 */
	public static List<String> getMonthBetween(String minDate, String maxDate) {
		ArrayList<String> result = new ArrayList<String>();
		//这里要注意 有的需求可能是用2020-01来表示20年第一周 格式就应该为yyyy-MM
		//如果是用2020-1来表示20年第一周 格式就应该为yyyy-M
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");// 格式化为年月
		try {
			Calendar min = Calendar.getInstance();
			Calendar max = Calendar.getInstance();

			min.setTime(sdf.parse(minDate));
			min.set(min.get(Calendar.YEAR), min.get(Calendar.MONTH), 1);

			max.setTime(sdf.parse(maxDate));
			max.set(max.get(Calendar.YEAR), max.get(Calendar.MONTH), 2);

			Calendar curr = min;
			while (curr.before(max)) {
				result.add(sdf.format(curr.getTime()));
				curr.add(Calendar.MONTH, 1);
			}

			// 实现排序方法
			Collections.sort(result, new Comparator<Object>() {
				@Override
				public int compare(Object o1, Object o2) {
					String str1 = (String) o1;
					String str2 = (String) o2;
					SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
					Date date1 = null;
					Date date2 = null;
					try {
						date1 = format.parse(str1);
						date2 = format.parse(str2);
					} catch (ParseException e) {
						e.printStackTrace();
					}

					if (date2.compareTo(date1) > 0) {
						return -1;
					}
					return 1;
				}
			});
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return result;
	}

	/**
	 * 获取两个年份之间的所有年份
	 *
	 * @param startDate 开始年份  格式 2022
	 * @param endDate 结束年份 格式 2023
	 */
	public static List<String> getYearBetween(String startDate, String endDate) {
		int startYear = Integer.parseInt(startDate);
		int endYear = Integer.parseInt(endDate);

		int yearsCount = endYear - startYear + 1;
		List<String> years = new ArrayList<>();

		for (int i = 0; i < yearsCount; i++) {
			years.add(String.valueOf(startYear + i));
		}

		return years;
	}

	/**
	 * 获取该月的第一天
	 * @param dateStr 月份  格式 2022-04
	 */
	public static String getFirstDayByMonth(String dateStr) {
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
		// 解析字符串为LocalDate对象
		YearMonth date = YearMonth.parse(dateStr, formatter);
		// 获取该月的第一天
		LocalDate firstDayOfMonth = date.atDay(1);
		// 将LocalDate对象转换回字符串
		return firstDayOfMonth.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
	}

	/**
	 * 获取该月的最后一天
	 * @param dateStr 月份  格式 2022-04
	 */
	public static String getLastDayByMonth(String dateStr) {
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
		// 解析字符串为LocalDate对象
		YearMonth date = YearMonth.parse(dateStr, formatter);
		// 获取该月的第一天
		LocalDate lastDayOfMonth = date.atEndOfMonth();
		// 将LocalDate对象转换回字符串
		return lastDayOfMonth.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
	}

	/**
	 * 获取两个日期之间的整点时间集合
	 *
	 * @param startTime 开始年份  格式 2024-05-15 00:00:00
	 * @param endTime 结束年份 格式 2024-06-30 00:00:00
	 */
	public static List<LocalDateTime> getDateBetween(LocalDateTime startTime, LocalDateTime endTime) {
		// 创建一个列表来存储整点时间
		List<LocalDateTime> hourlyTimes = new ArrayList<>();
		// 使用循环生成整点时间
		LocalDateTime currentTime = startTime;
		while (!currentTime.isAfter(endTime)) {
			hourlyTimes.add(currentTime);
			// 将时间增加一小时
			currentTime = currentTime.plusHours(1);
		}
		return hourlyTimes;
	}

	public static boolean HolidayCheck (LocalDateTime date) {
		LocalDate localDate = date.toLocalDate();
		HOLIDAYS.add(LocalDate.of(2024, 6, 8));
		HOLIDAYS.add(LocalDate.of(2024, 6, 9));
		HOLIDAYS.add(LocalDate.of(2024, 6, 10));
		HOLIDAYS.add(LocalDate.of(2024, 9, 15));
		HOLIDAYS.add(LocalDate.of(2024, 9, 16));
		HOLIDAYS.add(LocalDate.of(2024, 9, 17));
		HOLIDAYS.add(LocalDate.of(2024, 10, 1));
		HOLIDAYS.add(LocalDate.of(2024, 10, 2));
		HOLIDAYS.add(LocalDate.of(2024, 10, 3));
		HOLIDAYS.add(LocalDate.of(2024, 10, 4));
		HOLIDAYS.add(LocalDate.of(2024, 10, 5));
		HOLIDAYS.add(LocalDate.of(2024, 10, 6));
		HOLIDAYS.add(LocalDate.of(2024, 10, 7));
		DayOfWeek dayOfWeek = localDate.getDayOfWeek();
		boolean isWeekend = dayOfWeek == DayOfWeek.SATURDAY || dayOfWeek == DayOfWeek.SUNDAY;
		boolean isHoliday = HOLIDAYS.contains(localDate);
		return isWeekend || isHoliday;
	}


}
